import React, { useState, useMemo, useEffect, useRef } from 'react';
import { createModel } from 'hox';
import { message } from 'antd';
import { dictionaryImport, queryLogs } from './service.js';
import { useRequest } from '@umijs/hooks';

class Fields {
  tableParams = {};
  messageDetailVisible = false;
  messageDetailItem = {};
}
function useModel() {
  const initState = useMemo(() => new Fields(), []);

  const [state, dispatch] = useState({
    ...initState,
  });
  const clear = () => {
    dispatch({ ...initState });
  };

  const setState = payload => {
    dispatch(prevState => ({ ...prevState, ...payload }));
  };
  const { run, data } = useRequest(queryLogs, {
    manual: true,
  });

  return {
    run,
    state: {
      ...state,
      list: data?.data?.dataList || [],
      total: data?.data?.total || 0,
    },
    clear,
    setState,
  };
}

export default createModel(useModel);
